﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

public enum BODY_PARTS
{
    BODY_HEAD,
    BODY_TORSO,
    BODY_ARM_LEFT,
    BODY_ARM_RIGHT,
    BODY_LEG_LEFT,
    BODY_LEG_RIGHT,
    BODY_MAX,
};

namespace CharacterTool
{
    public class CBodyPart
    {
        // Public data members for easy access
        public float m_fAngle = 0.0f;
        public int m_nOriginX = 0, m_nOriginY = 0;
        public int m_nJointX = 0, m_nJointY = 0;
        public Rectangle m_Rect = new Rectangle(0, 0, 32, 32);
        public int m_nParentX = 0, m_nParentY = 0;
        public BODY_PARTS m_nBodyTypeID = BODY_PARTS.BODY_HEAD;

        public CAnimation[] m_AnimationBank = new CAnimation[4];

        // Constructor
        public CBodyPart(int parentX, int parentY, BODY_PARTS typeID)
        {
            m_nParentX = parentX;
            m_nParentY = parentY;
            m_nBodyTypeID = typeID;

            switch (m_nBodyTypeID)
            {
                case BODY_PARTS.BODY_HEAD:
                    m_Rect = new Rectangle(0, 0, 27, 24);
                    break;
                default:
                    break;
            }

            for (int i = 0; i < 4; i++)
                m_AnimationBank[i] = new CAnimation();

        }

        // Constructor
        public CBodyPart(int parentX, int parentY, BODY_PARTS typeID, Rectangle src)
        {
            m_nParentX = parentX;
            m_nParentY = parentY;
            m_nBodyTypeID = typeID;
            m_Rect = src;
        }

        public void Update()
        {
            m_nOriginX = Math.Abs(m_Rect.X - (m_Rect.Width >> 1));
            m_nOriginY = Math.Abs(m_Rect.Y - (m_Rect.Height >> 1));

            m_nJointX = m_nParentX - m_nOriginX;
            m_nJointY = m_nParentY - m_nOriginY;
        }

        public void Animate(int currentState)
        {
            m_AnimationBank[currentState].Play(ref m_fAngle);
        }
    }
}
